/**
 * 
 */
package com.cn.demo.springboot.quartz.config;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.listeners.JobListenerSupport;
import org.springframework.beans.factory.annotation.Autowired;

import com.cn.demo.springboot.dao.job.JobMapper;
import com.cn.demo.springboot.quartz.job.AbstractJob;

/**
 * @author tj
 *
 */
public class JobListenerImpl extends JobListenerSupport {

	@Autowired
	private JobMapper jobMapper;

	@Override
	public String getName() {
		return this.getClass().getName();
	}

	/**
	 * 任务执行前
	 */
	public void jobToBeExecuted(JobExecutionContext context) {
		Job jobInstance = context.getJobInstance();
		if(jobInstance instanceof AbstractJob) {
			AbstractJob job = (AbstractJob)jobInstance;
			job.setLock(true);
			
			// 进行数据库锁查询防止集群集体调用问题
			// 入果当前服务可以运行这修改为false
			
			if(true) {
				job.setLock(false);
			}
			
		}
		System.out.println("jobToBeExecuted");
	}

}
